﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.SystemService;

namespace CommunitySystem
{
    public partial class DataDictionaryItemWindow : ChildWindow
    {
        SystemService.SystemServiceClient client = new SystemService.SystemServiceClient();


        public DataDictionaryItemModel DDIModel = new DataDictionaryItemModel();

        public DataDictionaryItemWindow()
        {
            InitializeComponent();
            
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="PID"></param>
        public DataDictionaryItemWindow(int PID)
        {
            InitializeComponent();

            //父节点
            DDIModel.ParentId = PID;



            this.Loaded += new RoutedEventHandler(DataDictionaryItemWindow_Loaded);

        }

        /// <summary>
        /// 加载数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void DataDictionaryItemWindow_Loaded(object sender, RoutedEventArgs e)
        {
            //throw new NotImplementedException();

            
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {

            DDIModel.DictCode = TBDictCode.Text;
            DDIModel.DictValue = TBDictValue.Text;
            DDIModel.DictPinYin = TBPinYin.Text;
            DDIModel.Sec = Convert.ToInt32(sec.Text);

            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
        private string pattern = @"^[0-9]+([.]{1}[0-9]+){0,1}$";
        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if(!string.IsNullOrEmpty(((TextBox) sender).Text))
            {
                Match m = Regex.Match(((TextBox)sender).Text, pattern); // 匹配正则表达式
                if (!m.Success) // 输入的不是数字
                {
                    SilverlightMessageBoxLibrary.Message.ErrorMessage("只能输入数字！");
                    ((TextBox)sender).Text = "";
                    return;
                }
            }
            
        }
    }
}

